<%@ page language="java" isErrorPage="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java"  pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<script id="microloader" type="text/javascript" src="${pageContext.request.contextPath}/scripts/ext5/ext/build/ext-all.js"></script>
<script  type="text/javascript" src="${pageContext.request.contextPath}/scripts/ext5/ext/example/examples.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/ext5/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/styles/home.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/ext5/ext/example/example.css" />
<!DOCTYPE html>

<html>
<head>
    <script type="text/javascript">
        var ctx = "${pageContext.request.contextPath}";
        </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=MYRycSj3ZK1WZdLYEtzi2BDG"></script>
    <title>Hello, World</title>
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
    </style>

</head>
<body style="padding:0;">
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">

    var province='<%=request.getParameter("province")%>';
    var city='<%=request.getParameter("city")%>';
    var district='<%=request.getParameter("district")%>';
    var centerAddress='<%=request.getParameter("centerAddress")%>';
    var radius='<%=request.getParameter("radius")%>';
    var lng='<%=request.getParameter("lng")%>';
    var lat='<%=request.getParameter("lat")%>';
    function Rad(d){
        return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
    }

    function GetDistance(lat1,lng1,lat2,lng2){

        var radLat1 = Rad(lat1);
        var radLat2 = Rad(lat2);
        var a = radLat1 - radLat2;
        var  b = Rad(lng1) - Rad(lng2);
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
                Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
        s = s *6378.137 ;// EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000; //输出为公里
        //s=s.toFixed(4);
        return s;
    }

    var map = new BMap.Map("allmap");
//    var point = new BMap.Point(116.331398,39.897445);
//    map.centerAndZoom(point,14);
//    map.centerAndZoom("上海",14);
    var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
    map.addControl(top_left_control);
    map.enableScrollWheelZoom(true);
    //单击获取点击的经纬度
    var marker=null;
    var circle=null;
    map.addEventListener("click",function(e){
//        alert(e.point.lng + "," + e.point.lat);
        var point = new BMap.Point(e.point.lng,e.point.lat);
        if (null==marker) {
            marker = new BMap.Marker(point);// 创建标注
            circle = new BMap.Circle(point,radius,{strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5}); //创建圆
        }else{
            marker.setPosition(point);
            circle.setCenter(point);
        }
        map.addOverlay(marker);             // 将标注添加到地图中
        map.addOverlay(circle);             // 将标注添加到地图中
        marker.disableDragging();
        parent.Ext.getCmp('addressResponse.lng').setValue(e.point.lng)
        parent.Ext.getCmp('addressResponse.lat').setValue(e.point.lat)
    });
    function theLocation(city){
//        var city = document.getElementById("cityName").value;
        if(city != ""){
            map.centerAndZoom(city,14);      // 用城市名设置地图中心点
        }
    }
    if(lng!='null'&&lng!="0"){
        var defPoint = new BMap.Point(lng,lat);
        theLocation(defPoint);
        marker = new BMap.Marker(defPoint);// 创建标注
        circle = new BMap.Circle(defPoint,radius,{strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5}); //创建圆
        map.addOverlay(marker);             // 将标注添加到地图中
        map.addOverlay(circle);             // 将标注添加到地图中
        marker.disableDragging();
        parent.Ext.getCmp('addressResponse.lng').setValue(lng)
        parent.Ext.getCmp('addressResponse.lat').setValue(lat)
    }else{
        theLocation(province+city+district+centerAddress)
    }


</script>